package com.michael.study.listview;

import android.app.ActivityManager
import android.content.Context
import android.os.*
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.michael.study.listview.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity(), View.OnClickListener {

    private lateinit var mBinding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        mBinding.btnLinear.setOnClickListener(this)
        mBinding.btnGrid.setOnClickListener(this)
        mBinding.btnStagger.setOnClickListener(this)

        var cache = MemorySizeCalculator.Builder(this).build()
        //Log.d("lgq", "onCreate memoryCacheSize: " + cache.memoryCacheSize / 1024 / 1024)
        //Log.d("lgq", "onCreate arrayPoolSizeInBytes: " + cache.arrayPoolSizeInBytes / 1024 / 1024)
        //Log.d("lgq", "onCreate bitmapPoolSize: " + cache.bitmapPoolSize / 1024 / 1024)

        val activityManager =
            getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        Log.d("lgq", "onCreate: ${activityManager.memoryClass}")
        Log.d("lgq", "onCreate: ${activityManager.largeMemoryClass}")
    }

    override fun onClick(v: View?) {
        when (v?.id) {

            R.id.btn_linear -> {
                ActionUtil.startActivity(this,LinearMainActivity::class.java)
            }

            R.id.btn_grid -> {
                ActionUtil.startActivity(this,GridMainActivity::class.java)
            }

            R.id.btn_stagger -> {
                ActionUtil.startActivity(this,StaggerMainActivity::class.java)

            }

            else -> {
                //默认的
            }
        }
    }
}
